package com.example.hrsystem.data.source;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import androidx.room.Update;

import com.example.hrsystem.workflow.model.LeaveRequest;

import java.util.Date;
import java.util.List;

/**
 * 请假申请数据库访问接口
 * 提供对请假申请的数据库操作
 */
@Dao
public interface LeaveRequestDao {
    /**
     * 获取所有请假申请
     */
    @Query("SELECT * FROM leave_requests")
    List<LeaveRequest> getAllLeaveRequests();

    /**
     * 根据ID获取请假申请
     */
    @Query("SELECT * FROM leave_requests WHERE id = :id")
    LeaveRequest getLeaveRequestById(int id);

    /**
     * 根据流程实例ID获取请假申请
     */
    @Query("SELECT * FROM leave_requests WHERE processInstanceId = :processInstanceId")
    LeaveRequest getLeaveRequestByProcessInstanceId(int processInstanceId);

    /**
     * 根据申请人ID获取请假申请列表
     */
    @Query("SELECT * FROM leave_requests WHERE applicantId = :applicantId")
    List<LeaveRequest> getLeaveRequestsByApplicantId(int applicantId);

    /**
     * 根据状态获取请假申请列表
     */
    @Query("SELECT * FROM leave_requests WHERE status = :status")
    List<LeaveRequest> getLeaveRequestsByStatus(String status);

    /**
     * 根据请假类型获取请假申请列表
     */
    @Query("SELECT * FROM leave_requests WHERE leaveType = :leaveType")
    List<LeaveRequest> getLeaveRequestsByType(String leaveType);

    /**
     * 根据审批人ID获取待审批的请假申请列表
     */
    @Query("SELECT * FROM leave_requests WHERE approverId = :approverId AND status = 'PENDING'")
    List<LeaveRequest> getPendingLeaveRequestsByApproverId(int approverId);

    /**
     * 查询指定时间段内的请假申请
     */
    @Query("SELECT * FROM leave_requests WHERE (startTime <= :endDate AND endTime >= :startDate)")
    List<LeaveRequest> getLeaveRequestsInDateRange(Date startDate, Date endDate);

    /**
     * 插入请假申请
     */
    @Insert
    void insert(LeaveRequest request);

    /**
     * 更新请假申请
     */
    @Update
    void update(LeaveRequest request);

    /**
     * 删除请假申请
     */
    @Delete
    void delete(LeaveRequest request);
}